package com.vlin.scene.command.tuya;

import org.json.JSONObject;

import com.vlin.entity.scene.Command;
import com.vlin.scene.actuator.CommandProducer;
import com.vlin.scene.command.TuyaCommand;

public class TuyaCommandProducer implements CommandProducer {
	
	private static final int SUPPORT_TYPE = 2;

	@Override
	public Command produce(JSONObject command) {
		if(support(command)) {
			String did = command.getString("did");
			JSONObject commands = command.getJSONObject("cmd");
			TuyaCommand tuyaCommand = new TuyaCommand();
			tuyaCommand.setCommands(commands);
			tuyaCommand.setDid(did);
			tuyaCommand.setType(SUPPORT_TYPE);
			return tuyaCommand;
		}
		return null;
	}

	@Override
	public boolean support(JSONObject command) {
		if(command == null)
			return false;
		int type = command.getInt("type");
		if(type == SUPPORT_TYPE) {
			return true;
		}
		
		return false;
	}

}
